<?php

//error_reporting(E_ERROR | E_WARNING | E_PARSE);
mysql_connect(localhost, root, root);
@mysql_select_db(miniglider) or die("Unable to select database");
set_time_limit(0);
ini_set("memory_limit", "200M");
//$dateTime = date("Y-m-d",strtotime("-1 day"));
//$handle = fopen("http://192.168.0.185/log/test/$dateTime.'a'", "r");
$handle = fopen("/var/www/log/miniglider/log", "r");
while (!feof($handle)) {
    $buffer = fgets($handle, 10960);
    // $array[] = $buffer;
    $arr = json_decode($buffer, true);
    $id100 = $arr["data"];
    $arr2 = json_decode($id100, true);


    $id2 = $arr2["firstDay"];
    /*$id3 = $arr2["dayIap1Count"];
    $id4 = $arr2["dayIap2Count"];
    $id5 = $arr2["dayIap3Count"];
    $id6 = $arr2["dayIap4Count"];
    $id7 = $arr2["dayIap5Count"];
    $id8 = $arr2["dayIap6Count"];*/
    $id9 = $arr2["dayPage1TapCount"];
    $id10 = $arr2["dayPage2TapCount"];
    $id11 = $arr2["dayPage3TapCount"];
    $id12 = $arr2["dayPage4TapCount"];
    $id13 = $arr2["dayPage5TapCount"];
    $id14 = $arr2["upgradeB1Level"];
    $id15 = $arr2["upgradeB2Level"];
    $id16 = $arr2["upgradeB3Level"];
    $id17 = $arr2["upgradeB4Level"];
    $id18 = $arr2["upgradeB5Level"];
    $id19 = $arr2["upgradeB6Level"];

    $id20 = $arr2["upgradeB7Level"];
    $id21 = $arr2["upgradeB8Level"];
    $id22 = $arr2["upgradeB9Level"];

    $id23 = $arr2["upgradeB10Level"];
    $id24 = $arr2["upgradeB11Level"];
    $id25 = $arr2["upgradeB12Level"];
    $id26 = $arr2["upgradeB13Level"];
    $id27 = $arr2["upgradeB14Level"];
    $id28 = $arr2["upgradeB15Level"];
    $id29 = $arr2["upgradeB16Level"];
    $id30 = $arr2["upgradeB17Level"];
    $id301 = $arr2["upgradeB18Level"];
    $id302 = $arr2["upgradeB19Level"];
    $id303 = $arr2["upgradeB20Level"];

    $id31 = $arr2["playerA0Active"];
    $id32 = $arr2["playerA1Active"];
    $id33 = $arr2["playerA2Active"];
    $id34 = $arr2["playerA3Active"];
    $id35 = $arr2["playerA4Active"];
    $id36 = $arr2["playerA5Active"];
    $id361 = $arr2["playerA6Active"];
    $id37 = $arr2["dayIap1Count"];
    $id38 = $arr2["dayIap2Count"];
    $id39 = $arr2["dayIap3Count"];
    $id40 = $arr2["dayIap4Count"];
    $id41 = $arr2["dayIap5Count"];

    $id42 = $arr2["dayIap6Count"];
    $id43 = $arr2["totalGold"];
    $id44 = $arr2["dayItemUsedCountC1"];
    $id45 = $arr2["dayItemUsedCountC2"];
    $id46 = $arr2["dayItemUsedCountC3"];
    $id47 = $arr2["dayItemUsedCountC4"];
    $id48 = $arr2["dayItemUsedCountC5"];

    $id49 = $arr2["dayIapGold"];
    $id50 = $arr2["curGold"];
    $id51 = $arr2["dayItemBuyCountC1"];
    $id52 = $arr2["dayItemBuyCountC2"];
    $id53 = $arr2["dayItemBuyCountC3"];
    $id54 = $arr2["dayItemBuyCountC4"];
    $id55 = $arr2["dayItemBuyCountC5"];

    $id56 = $arr2["dayGameShotTime"];
    $id57 = $arr2["dayGameNormalDis"];
    $id58 = $arr2["itemCountC1"];
    $id59 = $arr2["itemCountC2"];  
    $id60 = $arr2["itemCountC3"];

    $id61 = $arr2["itemCountC4"];
    $id62 = $arr2["itemCountC5"];
    $id63 = $arr2["dayTotalTime"]; 
    $id64 = $arr2["dayUiLastTap"];
    $id65 = $arr2["dayGameNormalTime"];
    $id66 = $arr2["dayPlayCount"];
    $id67 = $arr2["totalPlayTime"];
    $id68 = $arr2["isCrack"];
    $id101 = $arr2["dayGameLongDis"];
    $id102 = $arr2["dayGameGold"];
    $id103 = $arr2["dayGameShotDis"];

    $id104 = $arr2["dayLoginCount"];
    $id105 = $arr2["dayUsedGold"];
    $id106 = $arr2["dayGameLongTime"]; 

    $id107 = $arr["gamename"];
    $id108 = $arr["deviceid"];
    $id109 = $arr["createdate"];
    $id110 = $arr["whatday"];

    $s = 0;
    foreach ((array) $arr as $item => $value) {   //Warning: Invalid argument supplied for foreach
        $s = count($value); //
    }
    for ($i = 0; $i < $s; $i++) {
    	
        //$firstDay = substr($id2,0,9);
        $firstDay = $id2;
        /*$dayIap1Count = $id3;
        $dayIap2Count = $id4;
        $dayIap3Count = $id5;
        $dayIap4Count = $id6;
        $dayIap5Count = $id7;
        $dayIap6Count = $id8;*/
        $dayPage1TapCount = $id9;
        $dayPage2TapCount = $id10;
        $dayPage3TapCount = $id11;
        $dayPage4TapCount = $id12;
        $dayPage5TapCount = $id13;

        $upgradeB1Level = $id14;
        $upgradeB2Level = $id15;
        $upgradeB3Level = $id16;
        $upgradeB4Level = $id17;
        $upgradeB5Level = $id18;
        $upgradeB6Level = $id19;

        $upgradeB7Level = $id20;
        $upgradeB8Level = $id21;
        $upgradeB9Level = $id22;

        $upgradeB10Level = $id23;

        $upgradeB11Level = $id24;
        $upgradeB12Level = $id25;
        $upgradeB13Level = $id26;
        $upgradeB14Level = $id27;
        $upgradeB15Level = $id28;
        $upgradeB16Level = $id29;
        $upgradeB17Level = $id30 ;
        $upgradeB18Level = $id301;
        $upgradeB19Level = $id302;
        $upgradeB20Level = $id303;

        $playerA0Active = $id31;
        $playerA1Active =  $id32;
        $playerA2Active = $id33;
        $playerA3Active = $id34;
        $playerA4Active = $id35; 
        $playerA5Active = $id36;
        $dayIap1Count = $id37;
        $dayIap2Count = $id38 ;
        $dayIap3Count = $id39;
        $dayIap4Count = $id40;
        $dayIap5Count = $id41;

        $dayIap6Count =  $id42;
        $totalGold =  $id43; 
        $dayItemUsedCountC1 = $id44;
        $dayItemUsedCountC2 =  $id45;
        $dayItemUsedCountC3 = $id46;
        $dayItemUsedCountC4 = $id47;
        $dayItemUsedCountC5 = $id48;

        $dayIapGold = $id49;
        $curGold = $id50;
        $dayItemBuyCountC1 = $id51;
        $dayItemBuyCountC2 = $id52;
        $dayItemBuyCountC3 =  $id53;
        $dayItemBuyCountC4 =  $id54;
        $dayItemBuyCountC5 =  $id55;

        $dayGameShotTime = $id56;
        $dayGameNormalDis = $id57;
        $itemCountC1 = $id58 ;
        $itemCountC2 = $id59 ; 
        $itemCountC3 = $id60 ;

        $itemCountC4 =  $id61;
        $itemCountC5 = $id62;
        $dayTotalTime =  $id63;
        $dayUiLastTap =  $id64 ;
        $dayGameNormalTime = $id65;
        $dayPlayCount = $id66 ;
        $totalPlayTime = $id67;
        $isCrack = $id68 ;
        $dayGameLongDis = $id101;
        //DataTime
        $dayGameGold = $id102;
        $dayGameShotDis = $id103;
        $dayLoginCount = $id104;
        $dayUsedGold = $id105;
        $dayGameLongTime = $id106;
        $gamename = $id107;
        $deviceid = $id108;
        $createdate = $id109;
        $whatday = $id110;
        //var_dump($dayIap1Count);


        mysql_query("INSERT INTO miniglider_query (firstlogindata,firstlogin,
        dayUI1TapCount,
        dayUI2TapCount,
        dayUI3TapCount,
        dayUI4TapCount,
        dayUI5TapCount,

        upgradeB1Level,
        upgradeB2Level,
        upgradeB3Level,
        upgradeB4Level,
        upgradeB5Level,
        upgradeB6Level,
        upgradeB7Level,
        upgradeB8Level,
        upgradeB9Level,

        upgradeB10Level,

        upgradeB11Level,
        upgradeB12Level,
        upgradeB13Level,
        upgradeB14Level,
        upgradeB15Level,
        upgradeB16Level,
        upgradeB17Level,
        upgradeB18Level,
        upgradeB19Level,
        upgradeB20Level,

        buyFigureA1,
        buyFigureA2,
        buyFigureA3,
        buyFigureA4,
        buyFigureA5,
        buyFigureA6,
        IAP1,
        IAP2,
        IAP3,
        IAP4,
        IAP5,
        IAP6,
        totalMoney,
        equipUsedC1,
        equipUsedC2,
        equipUsedC3,
        equipUsedC4,
        equipUsedC5,
        dayIapGold,
        nowMoney,
        equipBuyC1,
        equipBuyC2,
        equipBuyC3,
        equipBuyC4,
        equipBuyC5,
        dayPlayShortTime,
        dayPlayAvgDis,
        equipNowC1,
        equipNowC2,
        equipNowC3,
        equipNowC4,
        equipNowC5,
        dayTotalTime,
        lastUi,
        dayPlayAvgTime,
        dayPlayNowTime,
        totalTime,
        jailbreak,
        dayPlayLongDis,
        dayGetMoney,
        dayPlayShortDis, 
        dayPlayTime,
        dayUsedMoney,
        dayPlayLongTime,
        gamename,
        deviceid,
        createdate,
        date,
        dataTime) 
                    VALUES('$firstDay','$firstDay',
                    '$dayPage1TapCount',
                    '$dayPage2TapCount',
                    '$dayPage3TapCount',
                    '$dayPage4TapCount',
                    '$dayPage5TapCount',
                    '$upgradeB1Level',
                    '$upgradeB2Level',
                    '$upgradeB3Level',
                    '$upgradeB4Level',
                    '$upgradeB5Level',
                    '$upgradeB6Level',
                    '$upgradeB7Level',
                    '$upgradeB8Level',
                    '$upgradeB9Level',
                    '$upgradeB10Level',
                    '$upgradeB11Level',
                    '$upgradeB12Level',
                    '$upgradeB13Level',
                    '$upgradeB14Level',
                    '$upgradeB15Level',
                    '$upgradeB16Level',
                    '$upgradeB17Level',
                    '$upgradeB18Level',
                    '$upgradeB19Level',
                    '$upgradeB20Level',
                    '$playerA0Active',
                    '$playerA1Active',
                    '$playerA2Active',
                    '$playerA3Active',
                    '$playerA4Active',
                    '$playerA5Active',
                    '$dayIap1Count',
                    '$dayIap2Count',
                    '$dayIap3Count',
                    '$dayIap4Count',
                    '$dayIap5Count',
                    '$dayIap6Count',
                    '$totalGold',
                    '$dayItemUsedCountC1',
                    '$dayItemUsedCountC2',
                    '$dayItemUsedCountC3',
                    '$dayItemUsedCountC4',
                    '$dayItemUsedCountC5',
                    '$dayIapGold',
                    '$curGold',
                    '$dayItemBuyCountC1',
                    '$dayItemBuyCountC2',
                    '$dayItemBuyCountC3',
                    '$dayItemBuyCountC4',
                    '$dayItemBuyCountC5',
                    '$dayGameShotTime',
                    '$dayGameNormalDis',
                    '$itemCountC1',
                    '$itemCountC2',
                    '$itemCountC3',
                    '$itemCountC4',
                    '$itemCountC5',
                    '$dayTotalTime',
                    '$dayUiLastTap',
                    '$dayGameNormalTime',
                    '$dayPlayCount',
                    '$totalPlayTime',
                    '$isCrack',
                    '$dayGameLongDis',
                    '$dayGameGold',
                    '$dayGameShotDis',

                    '$dayLoginCount',
                    '$dayUsedGold',
                    '$dayGameLongTime',

                    '$gamename',
                    '$deviceid',
                    '$createdate',
                    '$createdate',
                    '$whatday')") or die(mysql_error());
    }
}
fclose($handle);

print "Import successful!<br>";

?>